﻿using System;
using System.Collections.Generic;
using TestApp.WebService;
using TestApp.Model.Data;
using System.Threading.Tasks;

namespace TestApp.Model.Managers
{
    public class StoresManager
    {
        private static volatile StoresManager instance;
        private static object syncRoot = new Object();

        private StoresManager() {
            StoreRadiusList = new List<int>() {5, 10, 15, 20, 25, 30, 35, 40, 45, 50 };
            StoreRadius = 20;
        }

        // Singleton Instance
        public static StoresManager Instance
        {
            get
            {
                if (instance == null)
                {
                    lock (syncRoot)
                    {
                        if (instance == null)
                            instance = new StoresManager();
                    }
                }

                return instance;
            }
        }


        // Search for stores by zip
        public async Task<List<Store>> SearchStoresByZip(String zipCode)
        {
           Stores = await StoresService.Instance.SearchStoresByZip(zipCode).ConfigureAwait(false);
           return Stores; 
        }

        // Store Radius List
        public List<int> StoreRadiusList
        {

            get;
            set;
        }

        // Store Radius
        public int StoreRadius
        {

            get;
            set;
        }

        // Stores
        public List<Store> Stores
        {
            get;
            set;
        }
    }
}
